package portal.monitor.dao.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import portal.monitor.dao.MonitorHost;
import portal.monitor.dao.mapper.MonitorHostMapper;

import java.util.List;

@Service
public class MonitorHostService {

    @Autowired
    MonitorHostMapper monitorHostMapper;

    public Integer insert(MonitorHost monitorHost){
        return monitorHostMapper.insert(monitorHost);
    }

    public Integer deleteByPrimaryKey(int hostId){
        return monitorHostMapper.deleteByPrimaryKey(hostId);
    }
    public Object deleteByPrimaryKeys(Integer[] hostIds){
        return monitorHostMapper.deleteByPrimaryKeys(hostIds);
    }

    public Integer updateByPrimaryKey(MonitorHost monitorHost){
        return monitorHostMapper.updateByPrimaryKey(monitorHost);
    }

    public MonitorHost selectByPrimaryKey(int hostId){
        return monitorHostMapper.selectByPrimaryKey(hostId);
    }

    public List<MonitorHost> selectAll(){
        return monitorHostMapper.selectAll();
    }


    public List<MonitorHost> selectByPage(int currentPage, int onePageCount){
        if(onePageCount<1||currentPage<1) return  null;
        int currentPosition = (currentPage-1)*onePageCount;
        return monitorHostMapper.selectByPage(currentPosition, onePageCount);
    }

    public Integer pageNum(Integer onePageCount){
        if(onePageCount<1) return -1;
        int hostNum = monitorHostMapper.hostNum();
        return (hostNum%onePageCount==0)?(hostNum/onePageCount):(hostNum/onePageCount+1);
    }

}
